﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace TV_Agenda_V2.Objects.Serializable
{
    public class TVAgendaSettings
    {
        [Category("Window")]
        [DisplayName("Window Location")]
        [Description("The location of the main form")]
        public Point Location { get; set; }

        [Category("Window")]
        [DisplayName("Window Size")]
        [Description("The size of the main form")]
        public Size Size { get; set; }

        [Category("Xml")]
        [DisplayName("Xml Show File")]
        [Description("The path to the xml file, with all the show data, will be stored")]
        [DefaultValue(@"%APPDATA%\tv agenda v2 show list.xml")]
        public String XmlShowFile { get; set; }

        [Category("Display")]
        [DisplayName("Episode format")]
        [Description("Defines the format of how the episodes are displayed:\n" +
            "%en = EpisodeNumber\n" +
            "%enZ = EpisodeNumber but with leading 0. Example: 01, 02, 10\n" +
            "%se = SeasonEpisodeNumber\n" +
            "%seZ = SeasonEpisodeNumber but with leading 0\n" +
            "%sn = SeasonNumber\n" +
            "%snZ = SeasonEpisodeNumber but with leading 0\n" +
            "%pn = ProdNumber\n" +
            "%ad = Airdate\n" +
            "%ln = Link\n" +
            "%t = Title")]
        [DefaultValue("%snx%seZ %ad")]
        public String EpisodeFormat { get; set; }

        [Category("Display")]
        [DisplayName("Date format")]
        [Description("Defines the format how dates are displayed.")]
        [DefaultValue("dd-MM-yyyy")]
        public String DateFormat { get; set; }

        Color _colorLast48Hours = Color.FromArgb(255, 192, 192);
        [XmlIgnore]
        internal Color ColorLast48Hours
        {
            get { return _colorLast48Hours; }
            set { _colorLast48Hours = value; }
        }
        [Category("Display")]
        [DisplayName("Color for past shows")]
        [Description("The color (in hex notation) for episodes that have been shown in the last 48 hours.")]
        [DefaultValue("#FFC0C0")]
        public string StringColorLast48Hours
        {
            get { return ColorTranslator.ToHtml(_colorLast48Hours); }
            set { ColorLast48Hours = ColorTranslator.FromHtml(value); }
        }

        Color _colorNext48Hours = Color.FromArgb(192, 255, 192);
        [XmlIgnore]
        internal Color ColorNext48Hours
        {
            get { return _colorNext48Hours; }
            set { _colorNext48Hours = value; }
        }

        [Category("Display")]
        [DisplayName("Color for upcoming shows")]
        [Description("The color (in hex notation) for episodes that will be shown in the next 48 hours.")]
        [DefaultValue("#C0FFC0")]
        public string StringColorNext48Hours
        {
            get { return ColorTranslator.ToHtml(_colorNext48Hours); }
            set { ColorNext48Hours = ColorTranslator.FromHtml(value); }
        }

        Color _colorBackground = Color.FromArgb(192, 192, 192);
        [XmlIgnore]
        internal Color ColorBackground
        {
            get { return _colorBackground; }
            set { _colorBackground = value; }
        }

        [Category("Display")]
        [DisplayName("Color for background")]
        [Description("The color (in hex notation) for episodes that will be shown outside the next/previous 48 hours.")]
        [DefaultValue("#FFFFFF")]
        public string StringColorBackground
        {
            get { return ColorTranslator.ToHtml(_colorBackground); }
            set { ColorBackground = ColorTranslator.FromHtml(value); }
        }

        public TVAgendaSettings()
        {
            XmlShowFile = @"%APPDATA%\tv agenda v2 show list.xml";
            EpisodeFormat = "%snx%seZ %ad";
            DateFormat = "dd-MM-yyyy";
            Location = new Point(90, 60);
            Size = new Size(560, 580);
            ColorLast48Hours = Color.FromArgb(255, 192, 192);  //light red
            ColorNext48Hours = Color.FromArgb(192, 255, 192);  //light green
            ColorBackground = Color.FromArgb(255, 255, 255);    //white
        }

        public void InitializeForm(Form form)
        {
            form.Location = Location;
            form.Size = Size;
        }

        public void LoadFromForm(Form form)
        {
            Location = form.Location;
            Size = form.Size;
        }
    }
}
